<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class IntencaoModel extends CI_Model {

    function __construct(){
        parent::__construct();
    }

    public function inserir($dados){
        $this->db->insert("intencao", $dados);
        return $this->db->insert_id();
    }

    public function update($id, $dados){
        $this->db->where("idIntencao", $id);
        $this->db->update("intencao", $dados);
    }

    public function delete($id){
        $this->db->where("idIntencao", $id);
        $this->db->delete("intencao");
    }

    public function getIntencao($idIntencao){
        $this->db->from("intencao");
        $this->db->where("idIntencao", $idIntencao);
        $query = $this->db->get();

        if( $query->num_rows() > 0 ) :
            return $query->row(0);

        else :
            return false;

        endif;
    }

    public function listar(){
        $query = $this->db->get("intencao");
        if( $query->num_rows() > 0 ) :
            return $query;

        else :
            return false;

        endif;
    }

    public function getIntencaoUsuario($idUsuario){
        $this->db->where("idUsuario", $idUsuario);
        $this->db->from("intencao");
        $query = $this->db->get();

        if( $query->num_rows() > 0 ) :
            return $query;
        
        else :
            return false;

        endif;
    }

    public function getIntencaoCategoria($idCategoria){
        $this->db->where("idCategoria", $idCategoria);
        $this->db->from("intencao");
        $query = $this->db->get();

        if( $query->num_rows() > 0 ) :
            return $query;

        else :
            return false;

        endif;
    }
   
}
